package com.watson.patterns.behavior.policy;

/*
* 策略模式相当于c++中的运算符重载
* */
public class Context {

    private Strategy strategy;

    public Context(Strategy strategy) {
        this.strategy = strategy;
    }

    public int executeStrategy(int num1, int num2) {
        return strategy.doOperation(num1, num2);
    }

    public static void main(String[] args) {
        Context context = new Context(new OperationAdd());
        int i = context.executeStrategy(19, 3);
        System.out.println(i);

        context = new Context(new OperationSub());
        int i1 = context.executeStrategy(18, 4);
        System.out.println(i1);

        context = new Context(new OperationMul());
        int i2 = context.executeStrategy(38, 3);
        System.out.println(i2);
    }
}
